package proto

import (
	

	
)

// MessageContainerTypeID is TL type id of MessageContainer.
const MessageContainerTypeID = 0x73f1f8dc

// MessageContainer contains slice of messages.
type MessageContainer struct {
	Messages []Message
}

// Encode implements bin.Decoder.
func ( *MessageContainer) ( *bin.Buffer) error {
	.PutID(MessageContainerTypeID)
	.PutInt(len(.Messages))
	for ,  := range .Messages {
		if  := .Encode();  != nil {
			return 
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *MessageContainer) ( *bin.Buffer) error {
	if  := .ConsumeID(MessageContainerTypeID);  != nil {
		return errors.Wrap(, "consume id of message container")
	}
	,  := .Int()
	if  != nil {
		return 
	}
	for  := 0;  < ; ++ {
		var  Message
		if  := .Decode();  != nil {
			return 
		}
		.Messages = append(.Messages, )
	}
	return nil
}

// Message is element of MessageContainer.
type Message struct {
	ID    int64
	SeqNo int
	Bytes int
	Body  []byte
}

// Encode implements bin.Encoder.
func ( *Message) ( *bin.Buffer) error {
	if .Bytes < 0 || .Bytes > 1024*1024 {
		return errors.Errorf("message length %d is invalid", .Bytes)
	}
	.PutLong(.ID)
	.PutInt(.SeqNo)
	.PutInt(.Bytes)
	.Put(.Body)
	return nil
}

// Decode implements bin.Decoder.
func ( *Message) ( *bin.Buffer) error {
	{
		,  := .Long()
		if  != nil {
			return 
		}
		.ID = 
	}
	{
		,  := .Int()
		if  != nil {
			return 
		}
		.SeqNo = 
	}
	{
		,  := .Int()
		if  != nil {
			return 
		}
		.Bytes = 
	}
	if .Bytes < 0 || .Bytes > 1024*1024 {
		return errors.New("message length is too big")
	}
	.Body = make([]byte, .Bytes)
	return .ConsumeN(.Body, .Bytes)
}