func (c *Codec) ReadRequestBody(out interface{}) error {
	const op = errors.Op("goridge_read_request_body")
	if out == nil {
		return nil
	}

	defer c.putFrame(c.frame)

	flags := c.frame.ReadFlags()

	switch { //nolint:dupl
	case flags&frame.CODEC_PROTO != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}

		// check if the out message is a correct proto.Message
		// instead send an error
		if pOut, ok := out.(proto.Message); ok {
			err := proto.Unmarshal(payload, pOut)
			if err != nil {
				return errors.E(op, err)
			}
			return nil
		}

		return errors.E(op, errors.Str("message type is not a proto"))
	case flags&frame.CODEC_JSON != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}
		return json.Unmarshal(payload, out)
	case flags&frame.CODEC_GOB != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}

		buf := c.get()
		defer c.put(buf)

		dec := gob.NewDecoder(buf)
		buf.Write(payload)

		err := dec.Decode(out)
		if err != nil {
			return errors.E(op, err)
		}

		return nil
	case flags&frame.CODEC_RAW != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}

		if raw, ok := out.(*[]byte); ok {
			*raw = append(*raw, payload...)
		}

		return nil
	case flags&frame.CODEC_MSGPACK != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}

		return msgpack.Unmarshal(payload, out)
	default:
		return errors.E(op, errors.Str("unknown decoder used in frame"))
	}
}
// ReadRequestBody fetches prefixed body data and automatically unmarshal it as json. RawBody flag will populate
// []byte lice argument for rpc method.
ReadRequestBody fetches prefixed body data and automatically unmarshal it as json. RawBody flag will populate
[]byte lice argument for rpc method.
// ReadRequestBody fetches prefixed body data and automatically unmarshal it as json . RawBody flag will populate // [] byte lice argument for rpc method .
func (c *Codec) ReadRequestBody(out interface{}) error {
	const op = errors.Op("goridge_read_request_body")
	if out == nil {
		return nil
	}
	defer c.putFrame(c.frame)
	flags := c.frame.ReadFlags()
	switch { 
	case flags&frame.CODEC_PROTO != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}
		if pOut, ok := out.(proto.Message); ok {
			err := proto.Unmarshal(payload, pOut)
			if err != nil {
				return errors.E(op, err)
			}
			return nil
		}
		return errors.E(op, errors.Str("message type is not a proto"))
	case flags&frame.CODEC_JSON != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}
		return json.Unmarshal(payload, out)
	case flags&frame.CODEC_GOB != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}
		buf := c.get()
		defer c.put(buf)
		dec := gob.NewDecoder(buf)
		buf.Write(payload)
		err := dec.Decode(out)
		if err != nil {
			return errors.E(op, err)
		}
		return nil
	case flags&frame.CODEC_RAW != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}
		if raw, ok := out.(*[]byte); ok {
			*raw = append(*raw, payload...)
		}
		return nil
	case flags&frame.CODEC_MSGPACK != 0:
		opts := c.frame.ReadOptions(c.frame.Header())
		if len(opts) != 2 {
			return errors.E(op, errors.Str("should be 2 options. SEQ_ID and METHOD_LEN"))
		}
		payload := c.frame.Payload()[opts[1]:]
		if len(payload) == 0 {
			return nil
		}
		return msgpack.Unmarshal(payload, out)
	default:
		return errors.E(op, errors.Str("unknown decoder used in frame"))
	}
}
func ( c * Codec ) ReadRequestBody ( out interface { } ) error { const op = errors . Op ( " " ) if out == nil { return nil } defer c . putFrame ( c . frame ) flags := c . frame . ReadFlags ( ) switch { case flags & frame . CODEC_PROTO != 0 : opts := c . frame . ReadOptions ( c . frame . Header ( ) ) if len ( opts ) != 2 { return errors . E ( op , errors . Str ( " " ) ) } payload := c . frame . Payload ( ) [ opts [ 1 ] : ] if len ( payload ) == 0 { return nil } if pOut , ok := out . ( proto . Message ) ; ok { err := proto . Unmarshal ( payload , pOut ) if err != nil { return errors . E ( op , err ) } return nil } return errors . E ( op , errors . Str ( " " ) ) case flags & frame . CODEC_JSON != 0 : opts := c . frame . ReadOptions ( c . frame . Header ( ) ) if len ( opts ) != 2 { return errors . E ( op , errors . Str ( " " ) ) } payload := c . frame . Payload ( ) [ opts [ 1 ] : ] if len ( payload ) == 0 { return nil } return json . Unmarshal ( payload , out ) case flags & frame . CODEC_GOB != 0 : opts := c . frame . ReadOptions ( c . frame . Header ( ) ) if len ( opts ) != 2 { return errors . E ( op , errors . Str ( " " ) ) } payload := c . frame . Payload ( ) [ opts [ 1 ] : ] if len ( payload ) == 0 { return nil } buf := c . get ( ) defer c . put ( buf ) dec := gob . NewDecoder ( buf ) buf . Write ( payload ) err := dec . Decode ( out ) if err != nil { return errors . E ( op , err ) } return nil case flags & frame . CODEC_RAW != 0 : opts := c . frame . ReadOptions ( c . frame . Header ( ) ) if len ( opts ) != 2 { return errors . E ( op , errors . Str ( " " ) ) } payload := c . frame . Payload ( ) [ opts [ 1 ] : ] if len ( payload ) == 0 { return nil } if raw , ok := out . ( * [ ] byte ) ; ok { * raw = append ( * raw , payload ... ) } return nil case flags & frame . CODEC_MSGPACK != 0 : opts := c . frame . ReadOptions ( c . frame . Header ( ) ) if len ( opts ) != 2 { return errors . E ( op , errors . Str ( " " ) ) } payload := c . frame . Payload ( ) [ opts [ 1 ] : ] if len ( payload ) == 0 { return nil } return msgpack . Unmarshal ( payload , out ) default : return errors . E ( op , errors . Str ( " " ) ) } }
ReadRequestBody fetches prefixed body data and automatically unmarshal it as json.
ReadRequestBody fetches prefixed body data and automatically unmarshal it as json .
//nolint:dupl // check if the out message is a correct proto.Message // instead send an error