78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/codec/prefix.rb', line 78
def encode(buf, field)
content_buf = ""
length = 0
content = field.get_sub_field(@content_id)
length = @value_codec.encode(content_buf, content) unless content.nil?
head = field.get_sub_field()
raise EncodingException.new "Missing header for encoding #{@id}" if head.empty?
head.set_value(length,@path,@separator) if length !=0
head_buf = ""
h_len = @length_codec.encode(head_buf,head)
if length != 0 && @total_length
length = head_buf.length + content_buf.length
head.set_value(length,@path,@separator)
head_buf = ""
@length_codec.encode(head_buf,head)
end
buf << head_buf
buf << content_buf
return head_buf.length + content_buf.length
end
|